from rendering import *
from gui import *
from vector import *
from entityManager import *
import pygame
import tower
import resources
from gui import *
import mapa
class hudBase:
    def __init__(self,surface):
        self.hudBase = r_object(surface,(0,120,0),800,100)
        self.energy = text(surface,"Energy:",(255,255,255))
        self.money = text(surface,"Money:",(255,255,255))
        self.buttons = []
        hud.append(self)
        self.surface = surface
        number = 0
        self.towerPlace = False
        self.page = 1
        self.canPress = True
        self.buttons.append(button(surface,vector(120,550),"<",self.prew))
        for i in range(0,len(tower.towerNames)):
            if i > 3:
                break
            self.buttons.append(button(surface,vector(200 +i*150,550),tower.towerNames[i],lambda number = i:self.newTower(number)))
        self.buttons.append(button(surface,vector(700,550),">",self.next))
    def next(self):
        self.page = self.page + 1
    def prew(self):
        self.page = self.page - 1
    def newTower(self,index):
        self.image = i_object("./Icons/"+tower.towerNames[index]+".png",self.surface)
        self.index = index
        self.buttonPressed = True
        self.towerPlace = True
    def switch(self):
        self.canPress = True
    def escape(self):
        pass
    def think(self):
        self.can = True
        self.energy.text = "Energy:"+str(resources.Energy)
        self.money.text = "Money:"+str(resources.Money)+"$"
        self.money.draw(vector(10,0))
        self.energy.draw(vector(600,0))
        if pygame.key.get_pressed()[pygame.K_ESCAPE] and self.canPress == True:
            self.canPress = False
            w = window(self.surface,vector(200,100),callOnKill = self.switch)
            w.addButton("Back to menu",self.escape)
        if self.towerPlace:
            if pygame.mouse.get_pressed()[0]==0:
                self.buttonPressed = False
            self.image.draw(vector((pygame.mouse.get_pos()[0]/10)*10,(pygame.mouse.get_pos()[1]/10)*10))
            if pygame.mouse.get_pressed()[0]==1 and self.buttonPressed != True and resources.Money - tower.towerPrices[self.index] >= 0:
                mPos = ((pygame.mouse.get_pos()[0]/10)*10,(pygame.mouse.get_pos()[1]/10)*10)
                self.towerPlace = False
                for pos in mapa.col:
                    if pos[0] == mPos:
                        self.can = False
                if self.can:
                    tower.towerEntities[self.index](self.surface,vector((mPos[0]/10)*10,(mPos[1]/10)*10))
            if pygame.mouse.get_pressed()[2]==1:
                self.towerPlace = False
        if pygame.mouse.get_pos()[1]>500 and self.towerPlace != True:
            self.hudBase.draw(vector(0,500))
            for button in self.buttons:
                button.think()
